<?php
include "./getSign.php";
include "./getData.php";
$url = "https://pay.mihuajinfu.com/paygateway/mbpay/order/v1";
$ch = curl_init($url);
$timeout = 6000;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER,0 );
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
//秘钥
$privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAIU0kIfFLJY5CzuljjVpi3tb/7S4SsqEyCfa0qtfP6zil+oQHMXv2lm1Ewp17GA4xCNrKNvCTNgqAOgoNybQqh3sZPvFLdGMt8BdZLjgFzaLf0O6WVnW+GfkkhNQNRJKg2tOIqwQ6/cn5Jx4GhJF7ZtBlgwAWIKnoY0NqBCxImf1AgMBAAECgYASI+du5fY9ewVBmTk1ousA4LWBCfv9enm7m7xG5FDKnY0srgcNGa31u4gdS5PmQrTLUgOdced/JLE87IUePxp7h/Obcqjgtho95A2Tk8iDdOAMClXTCUetchx9oCH9Nt/fr8K/dFXYw1piAO/xWvcMWQRHMDjWopAza/QdW4i7PQJBANSIUImpeA574MvkJrGUKw6rAawibceYZKCmP5Tg7rbkCmRl3snpajZNTBuYjQ26Eofot9ge3nLdPir8JrRN5msCQQCgct9twtcZPZ+J1JEcLjiRH2HpcjqXqI+l9o/vUG3I4qAOS+XFS260om7QY4JTPP2bzLPcCoTB7EPAdyf7kMMfAkBxncnIPgODYrAC753L0tTNy5diSSl8yTgKNbXJxhF3TiNMFrVqJVD1ZI8qNXw6eV2MsFkPvTjYGPQyEIg0XWyvAkEAha4P37hlVJ9WLBUR7ePIt4jpIAJPNQp43LLoS2C8h5Hh/udXgiEOFKv9Hdy6ubVoK4XLGPsejx/VdycQBfYfywJBAL83hLW712+Oz+tLa8AiseKYYDejDDJk7VF6YLBa5sB/i3qYiR07PxJ+g0JjBfQNbXktntJr4Slb74k/bMoh8ZE=";
$publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFNJCHxSyWOQs7pY41aYt7W/+0uErKhMgn2tKrXz+s4pfqEBzF79pZtRMKdexgOMQjayjbwkzYKgDoKDcm0Kod7GT7xS3RjLfAXWS44Bc2i39DullZ1vhn5JITUDUSSoNrTiKsEOv3J+SceBoSRe2bQZYMAFiCp6GNDagQsSJn9QIDAQAB";
$data = array(
	'merAccount' => '4213530d33654714b41c56721cc4e07f',//商户标识
	'merNo' => '10001213',//商户编号
	'time' => time(),//时间戳
	'orderId' => 'OR_00000011231123',//订单号
	'amount' => '1000',//交易金额(分)
	'product' => '手机',//商品
	'productDesc' => 'iphone',//商品描述
	'payWay' => 'WEIXIN',
	'payType' => 'JSAPI_WEIXIN',
	'openId' => 'ojmRm1jJzNSBK-6RxFFdNE30E4_4',
	'userIp' => '192.168.0.1',
	'returnUrl' => 'http://www.baidu.com',//前端页面回调地址
	'notifyUrl' => 'http://xxxxx.com'//后台回调地址
);
$data['sign'] = getSign($data,$privateKey);
$encode_data = encryptData($data,$privateKey);
$post_data = array(
	'merAccount' => '8d355cf180214715baf7d913a1357410',//商户标识
	'data' => $encode_data
);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  $ret = curl_exec($ch);
  curl_close($ch);
  echo '  return:'.$ret;
  $retjson = json_decode($ret,true);
  if(checkSign($retjson["data"],$publicKey)){
	  echo '验签成功';	  
  } else {
	  echo '验签失败';
  }
  
?>